package com.station.service.mapper;

import com.station.annotation.DataSource;
import com.station.vo.UnitVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description:
 * @Author: dongfangyu
 * @Date: 2025/10/9
 */

@Mapper
public interface UnitMapper {

    /**
     * 批量处理计量单位数据
     * @param unitVoList
     * @return int
     */
    @DataSource("base")
    @Insert({
            "<script>",
            "INSERT INTO unit (vendorId, unitName, unitCode, df, createDate, modifyDate) VALUES ",
            "<foreach collection='unitVoList' item='unit' separator=','>",
            "(#{unit.vendorId}, #{unit.unitName}, #{unit.unitCode}, #{unit.df}, #{unit.createDate}, #{unit.modifyDate})",
            "</foreach>",
            "ON DUPLICATE KEY UPDATE",
            "vendorId = VALUES(vendorId),",
            "unitName = VALUES(unitName),",
            "unitCode = VALUES(unitCode),",
            "df = VALUES(df),",
            "modifyDate = VALUES(modifyDate)",
            "</script>"
    })
    int batchInsertOrUpdateUnit(List<UnitVo> unitVoList);

    /**
     * 根据条件查询计量单位
     * @param vendorId
     * @param unitName
     * @return
     */
    @DataSource("base")
    @Select("select unitName,unitCode from unit where df = 0 and vendorId = #{vendorId} and unitName = #{unitName}")
    UnitVo queryUnitByCondition(@Param("vendorId") Long vendorId,@Param("unitName") String unitName);
}
